package com.c.yinyuezhushou.OnScrollListener;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.c.yinyuezhushou.Adapter.MusicRecAdapter;
import com.c.yinyuezhushou.MRetrofit.MusicItem;

import java.util.List;

public class MusicRecOnScrollListener extends RecyclerView.OnScrollListener {
    int i = 1;
    List<MusicItem> list;
    MusicRecAdapter musicRecAdapter;
    public MusicRecOnScrollListener(List<MusicItem> list, MusicRecAdapter musicRecAdapter) {
        this.list=list;
        this.musicRecAdapter=musicRecAdapter;
    }

    @Override
    public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
        if (newState==RecyclerView.SCROLL_STATE_IDLE)
        {   i++;
            if (list.size()-1>=i*16){
                musicRecAdapter.addData(list.subList(0,i*16));
            }else{
                musicRecAdapter.addData(list);
                musicRecAdapter.addLoad("gone");
            }
        } else{
            //viewPager.setUserInputEnabled(true);
        }
    }

    @Override
    public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
        super.onScrolled(recyclerView, dx, dy);
    }
}
